//
//  WBHomeViewController.swift
//  weibo
//
//  Created by apple on 2017/5/17.
//  Copyright © 2017年 hbjApple. All rights reserved.
//

import UIKit
private let cellReuseId = "HomeCellReuseId"

class WBHomeViewController: WBBaseViewController {
 lazy var dataSource = [String]()

    override func viewDidLoad() {
        super.viewDidLoad()
        loadData()

        setupUI()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    func loadData() {
        for i  in 0 ..< 15 {
            dataSource.insert(i.description, at: 0)
        }
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
// MARK: -设置界面
extension WBHomeViewController {
    //重写父类的方法
    override func setupUI() {
        super.setupUI()
        //设置导航栏按钮
        let btn = UIBarButtonItem.init(title: "好友", fontSize: 14, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange, target: self, action: #selector(showFriends))
        navItem.leftBarButtonItem = btn
           tableView?.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseId)
        tableView?.reloadData()
        //取消自定缩进 - 如果缩进20个点
        automaticallyAdjustsScrollViewInsets = false
        //设置内容缩进
        tableView?.contentInset = UIEdgeInsets(top: navBar.bounds.height,
                                               left: 0,
                                               bottom: tabBarController?.tabBar.bounds.height ?? 49,
                                               right: 0)
        
        
        
    }

    //显示好友
    func showFriends(){
        print(#function)
        let vc = WBDemoViewController()
        vc.hidesBottomBarWhenPushed = true
        navigationController?.pushViewController(vc, animated: true)
        
     
        
    }


}
//表格数据源方法
extension WBHomeViewController{
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return dataSource.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let  mcell = tableView .dequeueReusableCell(withIdentifier: cellReuseId, for: indexPath)
        mcell.textLabel?.text = dataSource[indexPath.row]
        return mcell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
}
